package com.webex.ta.hydra.gui.action;

import com.webex.ta.hydra.core.Command;
import com.webex.ta.hydra.core.CommandVisitor;
import com.webex.ta.hydra.core.engine.ResultCollector;
import com.webex.ta.hydra.gui.GuiPackage;

import java.awt.event.ActionEvent;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-15
 * Time: 10:25:34
 */
public class ClearResultsAction implements ActionHandler {
    private static Set<String> commands = new HashSet<String>();

    static {
        commands.add(ActionNames.CLEAR);
    }

    public Set<String> getActionNames() {
        return commands;
    }

    public void doAction(ActionEvent e) {
        GuiPackage gp = GuiPackage.getInstance();
        gp.getHydraTable().getModel().getRoot().traverse(new ResultCleaner());
        ResultCollector.getInstance().clear();
        gp.getIdeFrame().clearTestResults();
        gp.getHydraTable().repaint();
    }

    private class ResultCleaner implements CommandVisitor {
        public void visit(Command cmd) {
            cmd.clearTestResults();
        }
    }
}
